<html>
<head><meta charset="utf-8"><title>having fun with control flow · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html">having fun with control flow</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="197539225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197539225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197539225">(May 14 2020 at 11:24)</a>:</h4>
<p>I implemented string concatenation (with a length limit) with just <code>const_if_match</code> and it works even in associated constants using generic parameters: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=72c41dc07f92caf5ec5ebef5333491b4">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=72c41dc07f92caf5ec5ebef5333491b4</a></p>



<a name="197539257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197539257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197539257">(May 14 2020 at 11:24)</a>:</h4>
<p>would've been nicer with <code>loop</code>, but I'm not complaining</p>



<a name="197539264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197539264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197539264">(May 14 2020 at 11:24)</a>:</h4>
<p>this was painless to write (under 15 minutes)</p>



<a name="197593308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197593308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197593308">(May 14 2020 at 17:56)</a>:</h4>
<p>you call transmute unions "painless"? clearly you've been doing this for too long^^</p>



<a name="197618399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197618399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197618399">(May 14 2020 at 21:08)</a>:</h4>
<p>transmute unions are about as painless as it gets.</p>



<a name="197785057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197785057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197785057">(May 16 2020 at 08:51)</a>:</h4>
<p>except for <code>mem::transmute</code> of course... it remains kind of silly to not allow that in contexts where we allow union field reads</p>



<a name="197789282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197789282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197789282">(May 16 2020 at 10:35)</a>:</h4>
<p>sure, we can stabilize transmute outside of const fn, but I'd rather talk about unsafe stuff in const fn</p>



<a name="197790549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197790549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197790549">(May 16 2020 at 11:09)</a>:</h4>
<p>I think that's the same response I got when I proposed this first... at least half a year ago or so...</p>



<a name="197790560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197790560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197790560">(May 16 2020 at 11:09)</a>:</h4>
<p>oh but you even had a PR for it: <a href="https://github.com/rust-lang/rust/pull/64011">https://github.com/rust-lang/rust/pull/64011</a></p>



<a name="197790612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197790612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197790612">(May 16 2020 at 11:10)</a>:</h4>
<p>that PR discussion ends with a question for you <span class="user-mention" data-user-id="124288">@oli</span> :)</p>



<a name="197801939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197801939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197801939">(May 16 2020 at 15:55)</a>:</h4>
<p>O_o</p>



<a name="197801960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197801960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197801960">(May 16 2020 at 15:55)</a>:</h4>
<p>I... don't remember</p>



<a name="197882963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197882963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197882963">(May 18 2020 at 02:33)</a>:</h4>
<p>The problem with transmute is that I don't believe Rust has defined what happens if you invoke UB in const.</p>



<a name="197888175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197888175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197888175">(May 18 2020 at 04:29)</a>:</h4>
<p>It... hmm. Good question. Can we detect all instances when Miri invokes UB, <span class="user-mention" data-user-id="120791">@RalfJ</span>?</p>
<p>Because if so, then we should be able to just ("just"?) run Miri in const and check if UB is happening.</p>



<a name="197888252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197888252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197888252">(May 18 2020 at 04:31)</a>:</h4>
<p>Because as far as I know, the main "weakness" of Miri, in the sense of checking for UB, is that it can't check all possible invocations of a program: it needs a particular run, because it is an interpreter.<br>
But we're lucky here, because const is <strong>one</strong> particular run of a program.</p>



<a name="197960636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197960636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197960636">(May 18 2020 at 16:31)</a>:</h4>
<p>what do you mean by "Miri invokes UB"? Miri itself should never be UB. :D<br>
But Miri can indeed detect very well when the code it interprets invokes UB. For CTFE, some of these checks are disabled for performance reasons.</p>



<a name="197963819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197963819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197963819">(May 18 2020 at 16:54)</a>:</h4>
<p>It's also not necessary to detect UB, we just need to all sit together and talk about what it means to do UB, and whether more things are UB in const eval than in regular execution</p>



<a name="197963852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/197963852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#197963852">(May 18 2020 at 16:55)</a>:</h4>
<p>I'm using "just" very liberally here</p>



<a name="198162095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198162095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198162095">(May 20 2020 at 07:17)</a>:</h4>
<p>I'm wondering about this: maybe instead of defining exhaustively what is allowed or not from unsafe in const, we could just run Miri on it and see if it runs into UB? If not, the code compiles and all is well. If yes, then we reject the code, saying something along the lines of "this const code ran into UB. This is its Miri output:"</p>



<a name="198162328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198162328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198162328">(May 20 2020 at 07:20)</a>:</h4>
<p>Unless I'm understanding something way off, the only downside would be that Miri could be slower than something more specifically-tailored for the const-eval usage?</p>



<a name="198192914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198192914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198192914">(May 20 2020 at 12:50)</a>:</h4>
<p>yea the problem with that approach is that it will slow down the valid cases, too. What we can do though is make miri hijack const eval in order to insert validation and stacked borrows. This way when compiling with miri, you get miri for const eval, too, but when compiling normally with rustc you don't</p>



<a name="198254171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198254171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198254171">(May 20 2020 at 20:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/having.20fun.20with.20control.20flow/near/198192914">said</a>:</p>
<blockquote>
<p>yea the problem with that approach is that it will slow down the valid cases, too. What we can do though is make miri hijack const eval in order to insert validation and stacked borrows. This way when compiling with miri, you get miri for const eval, too, but when compiling normally with rustc you don't</p>
</blockquote>
<p>that would be interesting but seems orthogonal to the question of what we want to do during "regular" compilation.</p>



<a name="198254272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198254272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198254272">(May 20 2020 at 20:39)</a>:</h4>
<p>and there I think the main problem was one of teaching? we can come up with super restrictive rules for ptr comparison (only compare pointers within the same allocation) that I'd comfortably "sign off", but how do we communicate that safety conditions in const-eval are so different than at run-time?</p>



<a name="198254331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198254331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198254331">(May 20 2020 at 20:39)</a>:</h4>
<p>oh I got primed by some ptr comparison discussions elsewhere, this is about transmute</p>



<a name="198254467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198254467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198254467">(May 20 2020 at 20:40)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> what would you say is the main risk that transmute-triggered UB could cause during CTFE? AFAIK that was also mostly a teaching thing. I think on the engine level we are good.</p>



<a name="198254487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198254487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198254487">(May 20 2020 at 20:40)</a>:</h4>
<p>(we better be as <code>const</code> can already transmute via unions)</p>



<a name="198280835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198280835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198280835">(May 21 2020 at 02:44)</a>:</h4>
<blockquote>
<p>and there I think the main problem was one of teaching? we can come up with super restrictive rules for ptr comparison (only compare pointers within the same allocation) that I'd comfortably "sign off", but how do we communicate that safety conditions in const-eval are so different than at run-time?</p>
</blockquote>
<p>By explaining that we can compile more code in const-eval because we ultimately have the resources to execute it and check if it triggers UB or not. Therefore, we can be precisely as liberal as we want.</p>
<p>Whereas with non-const compilation you have to guarantee safety for unknown inputs. Which is way, way harder.</p>
<p>That said, maybe we can start by being just as conservative in const eval as we are in normal compilation. And then after understanding it better hands-on, we could relax the safety restrictions if there's an appealing scenario there.</p>



<a name="198297159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198297159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198297159">(May 21 2020 at 08:25)</a>:</h4>
<blockquote>
<p>Whereas with non-const compilation you have to guarantee safety for unknown inputs. Which is way, way harder.</p>
</blockquote>
<p>No, I think you misunderstood (see, this is hard to explain^^). We are talking about unsafe code, so we should compare unsafe const-code with unsafe runtime-code. Unsafe runtime-code has certain rules you have to follow, but it is up to you to follow them -- that's the point of unsafe, there is no guaranteed safety. Violating those rules is commonly called "Undefined Behavior". Also <a href="https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#undefined-behavior">see here</a>.<br>
With unsafe const-code, we have the same problem -- but the rules are different! So some code could be perfectly fine unsafe runtime-code but still be wrong unsafe const-code. And the compiler cannot tell you, because it's unsafe.</p>



<a name="198369031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369031">(May 21 2020 at 20:00)</a>:</h4>
<p>Ahhh. I see. I see now. The problem here is not about triggering what's runtime-UB in const-code. It is rather detecting what is unallowed const-code in an unsafe context, that at the same time is actually allowed runtime-code in an unsafe context.</p>



<a name="198369248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369248">(May 21 2020 at 20:01)</a>:</h4>
<p>No, detection when it happens is easy.</p>



<a name="198369312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369312">(May 21 2020 at 20:02)</a>:</h4>
<p>I forgot to add the restriction that const code is not allowed to do everything and anything otherwise-identical-runtime-code is allowed to do</p>



<a name="198369338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369338">(May 21 2020 at 20:02)</a>:</h4>
<p>But when you write a <code>const fn</code>, it might be wrong for inputs you didnt try, so you don't notice. or maybe you dont test your const-code ( <span aria-label="scream" class="emoji emoji-1f631" role="img" title="scream">:scream:</span> )</p>



<a name="198369372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369372">(May 21 2020 at 20:02)</a>:</h4>
<p>Mmm</p>



<a name="198369376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369376">(May 21 2020 at 20:02)</a>:</h4>
<p>I see</p>



<a name="198369446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369446">(May 21 2020 at 20:03)</a>:</h4>
<p>That makes sense</p>



<a name="198369451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369451">(May 21 2020 at 20:03)</a>:</h4>
<p>we have no way to tell if a <code>const</code> <em>function</em> with unsafe code in it is <em>well-behaved for all inputs</em> (halting problem yada yada)</p>



<a name="198369483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369483">(May 21 2020 at 20:03)</a>:</h4>
<p>so we have to teach people to write the right thing, like we do with normal unsafe code</p>



<a name="198369573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369573">(May 21 2020 at 20:04)</a>:</h4>
<p>that's why we permit union field access in <code>const</code> but not <code>const fn</code></p>



<a name="198369576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369576">(May 21 2020 at 20:04)</a>:</h4>
<p>And since <code>const</code> is an explicit directive to "please run this at compile time for me", we can't just... not run it at compile time if the input makes the function wrong</p>



<a name="198369628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369628">(May 21 2020 at 20:04)</a>:</h4>
<p>(and IMO we should do the same for <code>transmute</code>)</p>



<a name="198369662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369662">(May 21 2020 at 20:04)</a>:</h4>
<p>yeah we cannot do that either</p>



<a name="198369678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369678">(May 21 2020 at 20:04)</a>:</h4>
<p>I see</p>



<a name="198369686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369686">(May 21 2020 at 20:04)</a>:</h4>
<p>Dang</p>



<a name="198369715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369715">(May 21 2020 at 20:04)</a>:</h4>
<p>I thought we could escape the halting problem for this one</p>



<a name="198369718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369718">(May 21 2020 at 20:04)</a>:</h4>
<p>people have learned that unsafe Rust has rules they have to follow</p>



<a name="198369727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369727">(May 21 2020 at 20:04)</a>:</h4>
<p>Yas</p>



<a name="198369738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369738">(May 21 2020 at 20:04)</a>:</h4>
<p>they learned to check the reference and the nomcion and whatnot</p>



<a name="198369770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369770">(May 21 2020 at 20:05)</a>:</h4>
<p>but who will expect that the rules are <em>different</em> (stricter) when you put the same code in a <code>const fn</code>?</p>



<a name="198369914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369914">(May 21 2020 at 20:06)</a>:</h4>
<p>that's why we toyed around with the idea of having a separate marker, <code>unconst { ... }</code>, that makes people aware that something beyond normal unsafety is going on</p>



<a name="198369915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369915">(May 21 2020 at 20:06)</a>:</h4>
<p>Right</p>



<a name="198369933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369933">(May 21 2020 at 20:06)</a>:</h4>
<p>Hahahahaha</p>



<a name="198369943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369943">(May 21 2020 at 20:06)</a>:</h4>
<p>Okay, that's not a bad idea</p>



<a name="198369956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369956">(May 21 2020 at 20:06)</a>:</h4>
<p>I like a different marker</p>



<a name="198369973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198369973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198369973">(May 21 2020 at 20:06)</a>:</h4>
<p>For this one use case</p>



<a name="198370021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370021">(May 21 2020 at 20:07)</a>:</h4>
<p>but that needs a bunch of design to get a good handle on what the rules are, and an RFC for that marker</p>



<a name="198370065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370065">(May 21 2020 at 20:07)</a>:</h4>
<p>and nobody did all that work so far and I dont even know how many people like the idea of <code>unconst</code>^^</p>



<a name="198370078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370078">(May 21 2020 at 20:07)</a>:</h4>
<p>I mean, if it's gonna be its own art, an intersection of unsafe and const, yeah, a new keyword just for it makes sense</p>



<a name="198370123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370123">(May 21 2020 at 20:07)</a>:</h4>
<p>Yup</p>



<a name="198370133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370133">(May 21 2020 at 20:07)</a>:</h4>
<p>not to mention the issue that <code>unconst</code> is not a reserved keyword so we could break code by making it one</p>



<a name="198370207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370207">(May 21 2020 at 20:08)</a>:</h4>
<p>2021 edition todo-list</p>



<a name="198370324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370324">(May 21 2020 at 20:08)</a>:</h4>
<p>right but AFAIK for 2018 the directive was "no gratuit keyword reservations", so we should get an RFC accepted before the edition to get a keyword reserved...</p>



<a name="198370326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370326">(May 21 2020 at 20:08)</a>:</h4>
<p>And until then, just unsafe?</p>



<a name="198370353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370353">(May 21 2020 at 20:09)</a>:</h4>
<p>Ohh!</p>



<a name="198370357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370357">(May 21 2020 at 20:09)</a>:</h4>
<p>or a macro: <code>unconst!{ ... }</code></p>



<a name="198370361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370361">(May 21 2020 at 20:09)</a>:</h4>
<p>Okay</p>



<a name="198370372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370372">(May 21 2020 at 20:09)</a>:</h4>
<p>Yas</p>



<a name="198370385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370385">(May 21 2020 at 20:09)</a>:</h4>
<p>Or a macro</p>



<a name="198370554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370554">(May 21 2020 at 20:10)</a>:</h4>
<p>Well fwiw I second your idea of a special keyword for this</p>



<a name="198370594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370594">(May 21 2020 at 20:10)</a>:</h4>
<p>:D</p>



<a name="198370596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370596">(May 21 2020 at 20:10)</a>:</h4>
<p>I think the main argument for it is that the rules of the language are already different in that environment</p>



<a name="198370617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198370617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198370617">(May 21 2020 at 20:10)</a>:</h4>
<p>Different from unsafe and different from the default</p>



<a name="198416127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198416127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198416127">(May 22 2020 at 08:17)</a>:</h4>
<p>Ok I read up on the backlog</p>



<a name="198416189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198416189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198416189">(May 22 2020 at 08:18)</a>:</h4>
<p>Yes the issue is defining the differences between run-time unsafe and compile-time unsafe</p>



<a name="198416475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198416475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198416475">(May 22 2020 at 08:21)</a>:</h4>
<p>If we use unconst in const stuff, we'll need to use <code>unconst { unsafe { transmute(something) } }</code>? Or does it completely replace <code>unsafe</code>? The latter seems very odd to me. The problem that I see is that <code>transmute</code>, which is known to be unsafe because you can do <code>transmute::&lt;usize, &amp;u32&gt;</code>, is also unconst, because you can do <code>transmute::&lt;&amp;u32, usize&gt;</code> which we have a feature gate in the regular <code>x as *const u32 as usize</code> path. That cast is even <code>unsafe</code> even though it should just be <code>unconst</code>. My problem with an <code>unconst</code> scheme is that transmute and unions and raw ptr deref and probably others are both <code>unsafe</code> and <code>unconst</code> because they could both cause runtime UB and compile-time UB.</p>



<a name="198416605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198416605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198416605">(May 22 2020 at 08:22)</a>:</h4>
<p>I think we should only have the <code>unsafe</code> keyword (otherwise we have to have <code>unconst fn foo</code>, too?</p>



<a name="198416687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198416687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198416687">(May 22 2020 at 08:23)</a>:</h4>
<p>I mean, we already have the situation that there are different soundness rules on embedded and on OS based code</p>



<a name="198416816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198416816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198416816">(May 22 2020 at 08:25)</a>:</h4>
<p>Btw, the only thing I consider const-UB that is not also runtime-UB is that running a function with the same input (recursively through references) at runtime and at compile time gives different results</p>



<a name="198416838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198416838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198416838">(May 22 2020 at 08:25)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> do we have anything else that is const-UB but not runtime-UB?</p>



<a name="198486917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198486917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198486917">(May 22 2020 at 19:48)</a>:</h4>
<p>I imagined <code>unconst</code> would imply <code>unsafe</code>, but I see your point.</p>



<a name="198486958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198486958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198486958">(May 22 2020 at 19:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/having.20fun.20with.20control.20flow/near/198416838">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> do we have anything else that is const-UB but not runtime-UB?</p>
</blockquote>
<p>hm, let me re-read <a href="https://github.com/rust-lang/const-eval/blob/master/const_safety.md">stuff I wrote a while ago</a></p>



<a name="198487114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198487114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198487114">(May 22 2020 at 19:50)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/having.20fun.20with.20control.20flow/near/198416687">said</a>:</p>
<blockquote>
<p>I mean, we already have the situation that there are different soundness rules on embedded and on OS based code</p>
</blockquote>
<p>not really... soundness rules are given by the (nonexistent) Rust language spec and that one should not care about your environment. What example do you have in mind here?</p>



<a name="198487274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198487274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198487274">(May 22 2020 at 19:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/having.20fun.20with.20control.20flow/near/198416816">said</a>:</p>
<blockquote>
<p>Btw, the only thing I consider const-UB that is not also runtime-UB is that running a function with the same input (recursively through references) at runtime and at compile time gives different results</p>
</blockquote>
<p>I'd rather not define UB with anything as complicated and potentially undecidable as this.</p>



<a name="198487600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198487600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198487600">(May 22 2020 at 19:54)</a>:</h4>
<p>Instead I think of it in terms of the notes I <a href="https://github.com/rust-lang/const-eval/blob/master/const_safety.md">linked above</a>: the validity invariant for integers is slightly more restrictive in const-context, not allowing any pointers. (in fact ptr-to-int transmutes are even a problem in normal runtime semantics, there is no known formal semantics that supports them while also supporting all the optimizations LLVM does...) this means ptr-to-int casts should just be forbidden period, and trying to work around that restriction with transmutes is const-UB.</p>



<a name="198487727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198487727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198487727">(May 22 2020 at 19:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/having.20fun.20with.20control.20flow/near/198416838">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> do we have anything else that is const-UB but not runtime-UB?</p>
</blockquote>
<p>hm... no I cant think of anything besides ptr-to-int casts right now. even concurrency would work, with a deterministic scheduler. that is quite curious indeed.</p>



<a name="198488977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198488977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198488977">(May 22 2020 at 20:06)</a>:</h4>
<p>well, that and ptr equality testing, but that is related.</p>



<a name="198571681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198571681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198571681">(May 24 2020 at 07:50)</a>:</h4>
<p>one example of soundness that the rust spec cannot usefully fully specify is mmio</p>



<a name="198571733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198571733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198571733">(May 24 2020 at 07:52)</a>:</h4>
<p>That's just one of those "it's up to the environment" things</p>



<a name="198571746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198571746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198571746">(May 24 2020 at 07:53)</a>:</h4>
<p>that should mean the rust spec should be sufficiently flexible to make mmio a possible environment behavior</p>



<a name="198571751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198571751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198571751">(May 24 2020 at 07:54)</a>:</h4>
<p>but there's no "toggle" in the rust abstract machine that alters the way it works based on whether or not mmio is present</p>



<a name="198571792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198571792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198571792">(May 24 2020 at 07:54)</a>:</h4>
<p>mmio I think can be thought of as basically a particular kind of syscall interface, and of course syscall behavior is also not fully -- or rather, not at all -- specified by Rust</p>



<a name="198646656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198646656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198646656">(May 25 2020 at 08:39)</a>:</h4>
<p>I'm thinking about things like <code>*ptr::null_mut::&lt;u32&gt;() = 42</code> makes sense on certain platforms</p>



<a name="198646675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198646675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198646675">(May 25 2020 at 08:39)</a>:</h4>
<p>or yes, mmio</p>



<a name="198646777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198646777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198646777">(May 25 2020 at 08:41)</a>:</h4>
<p>dereferencing integer pointers of non-zst pointee type seems like something that is platform specific, but if I'm thinking about how miri would do it, there would indeed be no flag, just something that initializes the int2ptr map on startup instead of after allocation abstract allocs</p>



<a name="198646998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198646998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198646998">(May 25 2020 at 08:44)</a>:</h4>
<p>but back to mmio: when you have mmio, this is not just plain old memory. Simply reading from some mmio can theoretically crash your system. I know there's this discussion around references to mmio being bad because rust can insert spurious reads to references, but isn't this exactly the same discussion?</p>



<a name="198683789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198683789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198683789">(May 25 2020 at 16:12)</a>:</h4>
<p>I don't think that MMIO should happen at compile time. It would be nonsense.</p>
<p>You can certainly have const reads and writes for pointers to data in the const evaluation context, but "const mmio" is contradictory.</p>



<a name="198684927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198684927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198684927">(May 25 2020 at 16:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/having.20fun.20with.20control.20flow/near/198683789">said</a>:</p>
<blockquote>
<p>I don't think that MMIO should happen at compile time. It would be nonsense.</p>
</blockquote>
<p>we're not trying to do MMIO at compile-time, we're trying to figure out how to inform the user about the fact that some operation will differ between runtime and compile-time (e.g. by erroring at compile-time)</p>



<a name="198685027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198685027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198685027">(May 25 2020 at 16:28)</a>:</h4>
<p>e.g. casting a reference to a raw pointer and to a <code>usize</code> and doing something with that is not an operation that compile-time can do</p>



<a name="198685034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198685034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198685034">(May 25 2020 at 16:28)</a>:</h4>
<p>even if it's totally sound at runtime</p>



<a name="198691202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/198691202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#198691202">(May 25 2020 at 18:04)</a>:</h4>
<p>Right, and that seems like a very simple error message to print out.</p>



<a name="199244262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/199244262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#199244262">(May 30 2020 at 07:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/having.20fun.20with.20control.20flow/near/198646656">said</a>:</p>
<blockquote>
<p>I'm thinking about things like <code>*ptr::null_mut::&lt;u32&gt;() = 42</code> makes sense on certain platforms</p>
</blockquote>
<p>NULL is special-cased in the rust semantics. so NULL never makes sense in Rust. It is <em>always</em> UB to deref a NULL ptr, no matter what the hardware says, and even for a ZST.<br>
That is indeed a problem for certain platforms (e.g. wasm) -- but it is a problem well beyond CTFE so this is the wrong WG to discuss that issue. ;)</p>



<a name="199244335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/199244335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#199244335">(May 30 2020 at 07:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/having.20fun.20with.20control.20flow/near/198691202">said</a>:</p>
<blockquote>
<p>Right, and that seems like a very simple error message to print out.</p>
</blockquote>
<p>the problem is in the cases where we cant error. say you write a <code>const fn</code> which does such a wrong thing but don't notice -- you get no error. only much later one of your users stumbles upon the fact that your code is const-wrong, but now its assumptions are deeply engraved in its public API.</p>



<a name="199244345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/having%20fun%20with%20control%20flow/near/199244345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/having.20fun.20with.20control.20flow.html#199244345">(May 30 2020 at 07:47)</a>:</h4>
<p>See <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/having.20fun.20with.20control.20flow/near/198297159">this discussion</a> for some more background.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>